Function Reference

_GUICtrlComboGetLBTextLen

Retrieve the length, in characters, of a string in the list of a combo box

#Include <GuiCombo.au3>
_GUICtrlComboGetLBTextLen($h_combobox, $i_index)

 

Parameters

$h_combobox control id/control hWnd
$i_index Specifies the zero-based index of the string

 

Return Value

Success: Returns is the length of the string, in TCHARs, excluding the terminating null character.
If an ANSI string this is the number of bytes, and if it is a Unicode string this is the number of characters.
Failure: Returns $CB_ERR if the $i_index parameter does not specify a valid index.

 

Remarks

Under certain conditions, the return value is larger than the
actual length of the text. This occurs with certain mixtures of
ANSI and Unicode, and is due to the operating system allowing for
the possible existence of double-byte character set (DBCS) characters
within the text. The return value, however, will always be at least
as large as the actual length of the text; so you can always use it
to guide buffer allocation.

This behavior can occur when an application uses both ANSI functions
and common dialogs, which use Unicode.

To obtain the exact length of the text, use the WM_GETTEXT, LB_GETTEXT,
or CB_GETLBTEXT messages, or the GetWindowText function

 

Related

_GUICtrlComboSetEditSel

 

Example


#include <GuiConstants.au3>
#include <GuiCombo.au3>

Opt('MustDeclareVars',1)

Dim $Combo,$Btn_Exit,$Status,$msg

GuiCreate("ComboBox Get LB Text Len", 392, 254)

$Combo = GuiCtrlCreateCombo("", 70, 10, 270, 100,$CBS_SIMPLE)
GUICtrlSetData($Combo,"AutoIt|v3|is|freeware|BASIC-like|scripting|language")
$Btn_Exit = GuiCtrlCreateButton("Exit", 150, 180, 90, 30)
$Status = GUICtrlCreateLabel("",0,234,392,20,BitOR($SS_SUNKEN,$SS_CENTER))
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
        Case $msg = $Combo
            If(_GUICtrlComboGetCurSel($Combo) <> $CB_ERR) Then
                GUICtrlSetData($Status,"Length of Item[" & _GUICtrlComboGetCurSel($Combo) & "] = " & _GUICtrlComboGetLBTextLen($Combo, _GUICtrlComboGetCurSel($Combo)))
            EndIf
    EndSelect
WEnd
Exit